package datatypes;

import static org.junit.Assert.*;
import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

import de.dhbw.horb.inf2013.vierFarbenProblem.model.datatypes.AdjacencyListGraph;
import de.dhbw.horb.inf2013.vierFarbenProblem.model.datatypes.ColoredVertex;
import de.dhbw.horb.inf2013.vierFarbenProblem.model.datatypes.Graph;
import de.dhbw.horb.inf2013.vierFarbenProblem.model.datatypes.VertexNotSetException;

/**
 * The Class GraphTest.
 */
public class GraphTest {
	
	/** The graph. */
	private Graph graph;

	/**
	 * Instantiate graph.
	 */
	@Before
	public void instantiateGraph(){
		graph = new AdjacencyListGraph();
	}
	
	/**
	 * Adds the vertex single.
	 *
	 * @throws VertexNotSetException the vertex not set exception
	 */
	@Test
	public void addVertexSingle() throws VertexNotSetException {
		ColoredVertex v = new ColoredVertex(1);
		graph.addVertex(v);
		
		Assert.assertEquals(v, graph.getVertex(1));
	}
	
	/**
	 * Adds the vertex multi.
	 *
	 * @throws VertexNotSetException the vertex not set exception
	 */
	@Test
	public void addVertexMulti() throws VertexNotSetException {
		ColoredVertex v = new ColoredVertex(1);
		ColoredVertex v2 = new ColoredVertex(2);
		graph.addVertex(v);
		graph.addVertex(v2);
		
		Assert.assertEquals(v, graph.getVertex(1));
		Assert.assertEquals(v2, graph.getVertex(2));
	}
	
	/**
	 * Adds the edge from null.
	 *
	 * @throws VertexNotSetException the vertex not set exception
	 */
	@Test(expected=VertexNotSetException.class)
	public void addEdgeFromNull() throws VertexNotSetException {
		ColoredVertex v = new ColoredVertex(1);
		graph.addVertex(v);
		graph.addEdge(2, 1);
	}
	
	/**
	 * Adds the edge to null.
	 *
	 * @throws VertexNotSetException the vertex not set exception
	 */
	@Test(expected=VertexNotSetException.class)
	public void addEdgeToNull() throws VertexNotSetException {
		ColoredVertex v = new ColoredVertex(1);
		graph.addVertex(v);
		graph.addEdge(1, 2);
	}
	
	/**
	 * Adds the edge both null.
	 *
	 * @throws VertexNotSetException the vertex not set exception
	 */
	@Test(expected=VertexNotSetException.class)
	public void addEdgeBothNull() throws VertexNotSetException {
		graph.addEdge(1, 2);
	}
}
